//张一

#include <cstdio>
#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<int, double> polynomial;

    int n;
    int k;
    double v;

    for (int t = 0; t < 2; t++)
    {
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> k >> v;
            if (polynomial.count(k))
            {
                double nv = polynomial[k] + v;
                if (nv == 0)
                {
                    polynomial.erase(k);
                }
                else
                {
                    polynomial[k] = nv;
                }
            }
            else
            {
                polynomial[k] = v;
            }
        }
    }

    cout << polynomial.size();
    for (auto i = polynomial.rbegin(); i != polynomial.rend(); ++i)
    {
        printf(" %d %.1f", i->first, i->second);
    }
    cout << endl;
}